import java.io.*;
import java.util.ArrayList;

public class Test1 {
    public static void main(String[] args) throws IOException {
//         方法的封装
//        调用getstudentList方法，返回一个stus
        FileWriter fw = new FileWriter("d:\\女生寝室信息.txt");
        ArrayList<Student> stus = getStudentList();
        stus.sort((s1,s2)->{
            if (s1.getMenpai() == s2.getMenpai()){
                return s1.getChuangwei() - s2.getChuangwei();
            }else {
                return s1.getMenpai() - s2.getMenpai();
            }
        });

        for (int i = 0; i < stus.size(); i++) {
               Student stu = stus.get(i);
            System.out.println(stus.get(i));
            if ("女".equals(stu.getSex())){
                fw.write(stu.getXuehao()+","+stu.getYuanxi()+","+stu.getName()
                +","+stu.getLuodong()+","+stu.getLuoceng()+","+stu.getMenpai()
                +","+stu.getChuangwei());
                fw.write("\n");
            }
        }

          fw.close();

    }

    public static ArrayList<Student> getStudentList() throws IOException {
        File sushe = new File("d:\\sushe.txt");
        FileReader fr = new FileReader(sushe);
        BufferedReader br = new BufferedReader(fr);
        ArrayList<Student> stus = new ArrayList<>();
        String hang;
        while ((hang = br.readLine()) != null) {
            String[] hangs = hang.split(",");
            Student s = new Student();
            s.setXuehao(hangs[0]);
            s.setName(hangs[1]);
            s.setSex(hangs[2]);
            s.setYuanxi(hangs[5]);
            s.setLuodong(hangs[6]);
            s.setLuoceng(hangs[7]);
            s.setMenpai(Integer.valueOf(hangs[3]));
            s.setChuangwei(Integer.valueOf(hangs[4]));

            stus.add(s);

        }
        return stus;
    }

    public static int gethe() {
        int i = 1 + 2;
        return i;
    }

}
